package com.frostmourne.loreoriginex.utils;

import org.bukkit.ChatColor;

import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class MathUtils {

    private final static String regex = "([1-9]\\d*\\.?\\d*)|(0\\.\\d*[1-9])";

    public static List<Double> matchNumber(String str){
        List<Double> doubles = new ArrayList<>();
        Pattern pattern = Pattern.compile(regex);
        Matcher matcher = pattern.matcher(str);
        while (matcher.find()){
            String match = matcher.group(0);
            str = str.replace(match,"");
            matcher = pattern.matcher(str);
            doubles.add(Double.parseDouble(match));
        }
        return doubles;
    }

    public static double randomDouble(double min,double max){
        return Math.random() * (max-min)+min;
    }

    public static double format(double num){
        DecimalFormat df = new DecimalFormat("#.##");
        return Double.parseDouble(df.format(num));
    }

}
